package com.yanqu.road.server.cmd.activity.ghost;

import com.yanqu.road.entity.activity.ghost.config.GhostConfig;
import com.yanqu.road.pb.activity.GhostActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ghost.GhostModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.ghost.GhostMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_GHOST_SKIP_EVENT, desc = "鬼市跳过事件")
public class GhsotSkipEventCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        GhostConfig ghostConfig = GhostMgr.getGhostConfig();
        if (!ActivityMgr.activityInTime(ghostConfig.getActivityInfo())) {
            ret = GameErrorCode.E_GHOST_ACTIVITY_NO_OPEN;
            return;
        }

        GhostMgr.checkUserData(player);

        ret = player.getModule(GhostModule.class).skipEvent();
    }

    @Override
    public void sendData(GamePlayer player) {
        GhostActivityProto.GhostSkipEventRespMsg.Builder builder = GhostActivityProto.GhostSkipEventRespMsg.newBuilder();
        builder.setRet(ret);
        player.sendPacket(ClientProtocol.U_GHOST_SKIP_EVENT, builder);
    }
}
